﻿using System.Collections.ObjectModel;
using Core.Interfaces;
using System.Runtime.Serialization;

namespace Core.AbstractEntities
{
    /// <summary>
    /// Collection of items
    /// </summary>
    public abstract class HpCollection : ObservableCollection<HpElement>, IHpPile
    {
        #region IHpPile Members
        /// <summary>
        /// Add element to the list
        /// </summary>
        /// <param name="element">element to add</param>
        public abstract void AddElement(HpElement element);

        /// <summary>
        /// Send the element
        /// </summary>
        /// <param name="index">Position of the element in the list</param>
        /// <returns>An element</returns>
        public HpElement Get(int index)
        {
            return this.Items[index];
        }

        #endregion
        /// <summary>
        /// Elimate the last element put
        /// </summary>
        public void Pop()
        {
            this.Items.RemoveAt(Count - 1);
        }
        /// <summary>
        /// Switch the position between the elment n and n-1
        /// </summary>
        public void Swap()
        {
            this.MoveItem(Count - 1, Count - 2);
        }
        ///// <summary>
        ///// Duplicate the last value in the stack
        ///// </summary>
        //public void Dup()
        //{
        //    this.Add(this.Get(Count - 1));
        //}
        /// <summary>
        /// Remove N items of the stack
        /// </summary>
        /// <param name="numberOfItems"></param>
        public void Pop(int numberOfItems)
        {
            for (int i = 0; i <numberOfItems; i++)
            {
                Pop();
            }
        }
        /// <summary>
        /// Send the last element in the stack
        /// </summary>
        public HpElement Get()
        {
            return Get(Count - 1);
        }
    }
}
